//
//  ViewController.m
//  05-音量振动条
//
//  Created by J on 16/2/27.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *lightView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CAReplicatorLayer* repLayer = [CAReplicatorLayer layer];//复制图层可以复制图层里面的所有子层
    repLayer.frame = _lightView.bounds;
    [_lightView.layer addSublayer:repLayer];
    
    CALayer* layer = [CALayer layer];
    layer.anchorPoint = CGPointMake(0.5, 1);
    layer.position = CGPointMake(15, _lightView.bounds.size.height);
    layer.bounds = CGRectMake(0, 0, 30, 150);
    layer.backgroundColor = [UIColor whiteColor].CGColor;
    [_lightView.layer addSublayer:layer];
    [repLayer addSublayer:layer];
    
    CABasicAnimation * ani = [CABasicAnimation animation];
    ani.keyPath = @"transform.scale.y";
    ani.toValue = @0.1;
    ani.duration = 0.5;
    ani.repeatCount = CGFLOAT_MAX;
    
    //设置动画反转
    ani.autoreverses = YES;
    
    //复制子层 表示复制层里面有多少个子层 包括原始层
    repLayer.instanceCount = 5;
    //设置复制的子层偏移量  不包括原始层,相对于原始层x偏移   后面的复制层都是相对于前一个复制层的
    repLayer.instanceTransform = CATransform3DMakeTranslation(45, 0, 0);
    //设置复制层的动画延迟时间 后面的复制层都是相对于前一个复制层的
    
    repLayer.instanceDelay = 0.1;
    //如果设置了原始层背景色 这个就不需要设置
    repLayer.instanceColor = [UIColor orangeColor].CGColor;//想要这里设置什么 就显示什么颜色 原始层显示为白色 才行
    
//    repLayer.instanceGreenOffset = -0.5;
    repLayer.instanceRedOffset = -0.2;
//    repLayer.instanceBlueOffset = -0.5;
    repLayer.instanceAlphaOffset = 0.2;
    [layer addAnimation:ani forKey:nil];
    
    
    
 

}



@end
